using UnityEngine;
using Cyys.Inventory;

public class CharacterManager : Singleton<CharacterManager>
{
    [Header("所有可用角色配置")]
    public PlayerDetails_SO playerData;


    // [Header("当前选择的角色")]
    // public int currentPlayerID;
    [HideInInspector] public PlayerDetails currentPlayer;

    [Header("角色预制体")]
    public GameObject playerPrefab;

    private GameObject playerCanvas;

    public override void Awake()
    {
        base.Awake();
    }

    private void OnEnable()
    {
        // EventHandler.AfterSceneLoadEvent += OnAfterSceneLoadEvent;
        // EventHandler.StartFollowingPath += OnStartFollowingPath;
    }

    private void OnDisable()
    {
        // EventHandler.AfterSceneLoadEvent -= OnAfterSceneLoadEvent;
        // EventHandler.StartFollowingPath -= OnStartFollowingPath;
    }




    // 设置当前角色
    public void SetCharacter(int currentPlayerID)
    {
        if (playerData.playerDetailList.Count > 0 && currentPlayerID == 0)
        {
            currentPlayer = playerData.playerDetailList[0];
        }
        else
        {
            currentPlayer = playerData.GetPlayerDetails(currentPlayerID);
        }

        EventHandler.CallCharacterChanged(currentPlayer);
    }

    private void Start()
    {
        //地图上创建角色
        playerCanvas = GameObject.FindWithTag("PlayerCanvas");
        Instantiate(playerPrefab, playerCanvas.transform);
        CharacterManager.Instance.SetCharacter(InventoryManager.Instance.playerID);
    }
    
}
